package com.cmhi.softmbh.util;

import com.softmbh.kellyplatform.util.MacUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class TMallUtils {

    public static Map<String, String> tMallCmeiProductTypeCode = new HashMap();

    static {
        tMallCmeiProductTypeCode.put("11101566", "500801");
        tMallCmeiProductTypeCode.put("11102625", "500801");
        tMallCmeiProductTypeCode.put("11102552", "501344");
        tMallCmeiProductTypeCode.put("11103508", "501840");
        tMallCmeiProductTypeCode.put("11103510", "501860");
    }

    public static String getDeviceId() {
        String deviceId = "";
        String cmei = execCmd("getprop persist.sys.imei");
        String productTypeCode = tMallCmeiProductTypeCode.get(cmei.substring(0,8));
        String mac = MacUtils.getMac();
        deviceId = "CMCC-"+productTypeCode+"-"+mac;
        return deviceId;
    }


    /**
     * @return 执行命令后返回结果
     */
    public static String execCmd(String cmd) {
        Process process= null;
        try {
            process = Runtime.getRuntime().exec(cmd);
            InputStreamReader ir=new InputStreamReader(process.getInputStream());
            BufferedReader input=new BufferedReader(ir);
            return input.readLine();
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

}
